package service.impl;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

import pojo.User;
import dao.UserHandle;
import dao.impl.UserHandleImpl;
import service.UserHandleService;
import utils.Format;

public class UserHandleServiceImpl implements UserHandleService {
	UserHandle uh ;
	
	public UserHandleServiceImpl() {
		super();
		this.uh = new UserHandleImpl();
	}

	@Override
	public int addUser(String uname, String sal, String birth, String sex,
			byte[] avatar) {
			User user = new User();
			user.setUname(uname);
			double sals = Double.parseDouble(sal);
			user.setSal(sals);
			Date birthdate;
			try {
				birthdate = Format.sdf.parse(birth);
				user.setBirth(birthdate);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			user.setSex(sex);
			user.setAvatar(avatar);
			uh.addUser(user);
		return 1;
	}

	@Override
	public List<User> loadUsers() {
		List<User> users = uh.loadUsers();
		return users;
	}

}
